<template>
	<u-popup :show="show" @close="close" closeable   @touchmove.stop.prevent="moveHandle">
		<div class="myPop">
			<div class="myTitle" v-if="form.result==0">审核通过</div>
			<div class="myTitle mustTag" v-if="form.result==1">审核驳回</div>
			<div class="myForm">
				<u-form ref="form" :model='form'>
					<u-form-item :required='form.result==1' label="备注">
						<u--textarea v-model="form.remark" placeholder="请输入审核意见" maxlength='100'></u--textarea>
					</u-form-item>
				</u-form>
			</div>
			<div class="myText signDiv" style="margin-left: 10px;" v-if="flag!=9">
				<div style="display: flex;align-items: center;">
					<div><span class="mustTag">*</span>电子签名：</div>
					<div v-if="form.signature">
						<image :src="form.signature" style="width: 150px;height: 30px;" mode="aspectFit">
						</image>
					</div>
					<div v-else class="signBtn" @click="goSign()">暂无电子签名，点击去设置</div>
				</div>
			</div>
			<div class="myBtn">
				<u-button type='primary' text="提交" @click="confirm" throttleTime='1000'></u-button>
			</div>
		</div>
		<u-overlay :show="bgFlag"></u-overlay>
	</u-popup>
</template>
<script>
	import {
		okTaskApprove,
		okDeptApprove
	} from "@/api/taskMng/index.js"
	import {
		getSign
	} from "@/api/system/user"
	export default {
		data() {
			return {
				show: false,
				bgFlag: false,
				flag: 0, //0任务审核，1作业审核，2报告审核，3报告签发,11检测机构
				form: {
					approveId: '',
					result: '', //0同意。1驳回
					remark: '',
					signature: ''
				}
			}
		},
		methods: {
			moveHandle(){},
			open(flag, result, approveId) {
				this.show = true
				this.bgFlag = false
				this.flag = flag
				this.form.approveId = approveId
				this.form.result = result
				this.form.remark = ''
				this.load()
			},
			close() {
				this.show = false
			},
			goSign() {
				this.show = false
				uni.navigateTo({
					url: '/pages/mine/info/edit'
				})
			},
			load() {
				let req = {
					userId: this.$store.state.user.userId
				}
				getSign(req).then(res => {
					this.form.signature = res.data.signature
				})
			},
			confirm() {
				if (this.form.result == 1 && !this.form.remark) {
					this.$toast('备注不能为空')
					return
				}
				if (this.flag != 9 && !this.form.signature) {
					this.$toast('电子签名不能为空')
					return
				}
				if (this.flag == 9) {
					uni.showLoading()
					this.bgFlag = true
					let req = {
						approveResult: this.form.result,
						departmentId: this.form.approveId,
						remark: this.form.remark
					}
					okDeptApprove(req).then(res => {
						uni.showToast({
							title: '审核成功',
							mask: true,
							complete() {
								setTimeout(() => {
									uni.navigateBack({
										complete() {
											uni.$emit('approveListUpdate')
										}
									})
								}, 1000)
							}
						})
					}).finally(e => {
						this.bgFlag = false
					})
				}
				if (this.flag != 9) {
					uni.showLoading()
					this.bgFlag = true
					okTaskApprove(this.form).then(res => {
						uni.showToast({
							title: '审核成功',
							complete() {
								setTimeout(() => {
									uni.navigateBack({
										complete() {
											uni.$emit('approveListUpdate')
										}
									})
								}, 1000)
							}
						})
					}).finally(e => {
						this.bgFlag = false
					})
				}

			}
		}
	}
</script>
<style scoped lang="scss">
	.signBtn {
		color: $u-primary !important;
	}

	.mustTag {
		color: $u-error;
	}
</style>